<%@page import="java.text.SimpleDateFormat"%>
<%@page import="beans.Teacherbean"%>
<%@page import="dao.Teacher"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<%
	    Teacher teacher = new Teacher();
				String grade = "", courseName = "", rank = "", sex = "", birthString="";
				if (request.getQueryString() != null) {
					String id = request.getParameter("teacherId");
					teacher = (new Teacherbean()).getTeacherById(id);
					grade = teacher.getCourseid().substring(0, 2);
					courseName = teacher.getCourseid().substring(2);
					rank = teacher.getRank();
					sex = teacher.getSex();
					birthString = (new SimpleDateFormat("yyyy-MM-dd")).format(teacher.getBirthdate());
				}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>修改教师信息</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body {
	font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica,
		sans-serif;
	color: #4f6b72;
	text-align: center;
	background: #E6EAE9;
}

#container {
	margin-left: auto;
	margin-right: auto;
	width: 550px;
	height: 600px;
	background: #f8f8f8;
	border: 2px solid #777;
	display: block;
	vertical-align: middle;
}

.ele {
	margin-top: 30px;
	margin-botton: 30px;
	text-align: center;
	width: 100%;
	display: block;
	vertical-align: middle;
}
</style>
<script type="text/javascript" src="./js/My97DatePicker/WdatePicker.js"
	defer="defer"></script>
<script type="text/javascript">
function checkData(){
	var name = document.getElementById("teacherName").value.trim();
	var sex = document.getElementById("sex").value.trim();
	var birthDate = document.getElementById("birthDate").value.trim();
	var grade = document.getElementById("grade").value.trim();
	var courseName = document.getElementById("courseName").value.trim();
	var rank = document.getElementById("rank").value.trim();
	var des = document.getElementById("des").value.trim();
	if(grade !="" && name !="" && sex !="" && birthDate !="" && courseName !="" && rank !="" && des !=""){	
			return true;					
	}else{
		alert("请填写完整！");
		return false;
	}
}

function select(){
	var sel = document.getElementById("grade").options;
	   for(var i=0;i<sel.length;i++){
	       if(<%=grade%> ==sel[i].value){sel[i].selected=true;break;}
	   }
	   
	   var sel2 = document.getElementById("courseName").options;
	   for(var i=0;i<sel2.length;i++){
	       if(<%=courseName%> ==sel2[i].value){sel2[i].selected=true;break;}
	   }
	   
	   var sel3 = document.getElementById("rank").options;
	   for(var i=0 ;i<sel3.length;i++){
	       if(<%=rank%> ==sel3[i].value){sel3[i].selected=true;break;}
	   }
	    
	   var radio1 = document.getElementsByName("sex");
	   for(var i=0;i<radio1.length;i++){
	       if(<%=sex%> ==radio1[i].value){radio1[i].checked="checked";break;}
	   }
	   
	}

</script>
</head>

<body>
	
	<h2>修改教师信息</h2>
	<div id="container">
		<form name="courseForm" method="post"
			action="./servlet/TeacherManageServlet?action=modify"
			onsubmit="return checkData()">
			<input type="hidden" name="teacherId" name="teacherId"
				value="<%=teacher.getTeacherid()%>">
			<div class="ele">
				<label> 姓名： </label> <input type="text" name="teacherName"
					id="teacherName" value="<%=teacher.getName()%>">
			</div>
			<div class="ele">
				<label> 性别： </label> <input type="radio" name="sex" value="0">
				男 <input type="radio" name="sex" value="1"> 女
			</div>
			<div class="ele">
				<label> 出生日期： </label> <input type="text" name="birthDate"
					id="birthDate" readonly="readonly"
					value="<%=birthString %>"> <img
					onclick="WdatePicker({el:'birthDate'})"
					src="./js/My97DatePicker/skin/datePicker.gif" width="16"
					height="22" align="absmiddle">
			</div>

			<div class="ele">
				<label> 所在年级： </label> <select name="grade" id="grade">
					<option value="choose">请选择年级</option>
					<option value="01">初中一年级</option>
					<option value="02">初中二年级</option>
					<option value="03">初中三年级</option>
					<option value="04">高中一年级</option>
					<option value="05">高中二年级</option>
					<option value="06">高中三年级</option>
				</select> &nbsp;&nbsp;&nbsp;&nbsp; <label> 所教科目： </label> <select
					name="courseName" id="courseName">
					<option value="choose">请选择科目</option>
					<option value="01">语文</option>
					<option value="02">数学</option>
					<option value="03">英语</option>
					<option value="04">物理</option>
					<option value="05">化学</option>
					<option value="06">生物</option>
					<option value="07">历史</option>
					<option value="08">政治</option>
					<option value="09">地理</option>
				</select>
			</div>
			<div class="ele">
				<label> 级别： </label> <select name="rank" id="rank">
					<option value="0">普通教师</option>
					<option value="1">年级组长</option>
				</select>
			</div>
			<div class="ele">
				<label align="absmiddle">简介：</label>
				<textarea rows="6" cols="50" name="des" id="des"><%=teacher.getDescription() %>
			</textarea>
			</div>
			<div class="ele">
				<input type="submit" value="提交"> <input type="reset"
					value="取消">
			</div>
		</form>
		
	</div>
	<%
	    if (request.getAttribute("success") != null) {
			String str = (String) request.getAttribute("success");
			if ("true".equals(str)) {
			    out.write("<script>alert('修改成功！')</script>");
			} else if ("false".equals(str)) {
			    out.write("<script>alert('修改失败！')</script>");
			}
	    }
	%>
	<script>select();</script>
</body>
</html>
